<?php

namespace Platform\Models\Organize;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 组织模型
 * Class Organize
 * @package Platform\Models\Organize
 */
class Organize extends Model
{
    use SoftDeletes;

    protected $table = 'organizes';

    public static $STATE_LOCK = 0;
    public static $STATE_NORMAL = 1;

    protected $guarded = [];

    /**
     * 获取绑定组织成员表关系
     * @return HasMany
     */
    public function leader() : HasMany
    {
        return $this->hasMany(Leader::class,'organize_id','id');
    }

    /**
     * 绑定组织成员角色关系
     * @return HasMany
     */
    public function role() : HasMany
    {
        return $this->hasMany(LeaderRole::class, 'organize_id', 'id');
    }

    /**
     * 获取当前组织下的默认角色
     * @return Model|HasMany|null|object
     */
    public function getDefaultRole()
    {
        return $this->role()->where('is_default',1)->first();
    }

}
